<script setup lang="ts">
import DoctorCard from './doctor-card.vue'
// import { useWidth } from '@/composable/useWidth'
// const { width } = useWidth()
import { useWindowSize } from '@vueuse/core'
import { homePageDoc } from '@/api/home'
import type { homePageDocApiRows } from '@/types/home'
import { ref } from 'vue'
const { width } = useWindowSize()
const list = ref<homePageDocApiRows[]>([])
const getData = async () => {
  const res = await homePageDoc({
    current: 1,
    pageSize: 5
  })
  list.value = res.data.rows
  console.log('推荐列表', res)
}
getData()

/*
调用ts接口
  1：定义api
  2:写请求参数的类型并在api中使用
  3：在页面导入调用接口api，打印返回值
  4：定义返回值的类型并在api中使用
  5：存储数据并渲染

*/
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <van-swipe :show-indicators="false" :loop="false" :width="(150 / 375) * width">
        <van-swipe-item v-for="i in list" :key="i.id">
          <DoctorCard :item="i"></DoctorCard>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: scroll;
  }
}
</style>
